package A1_数组;

public class LC_209长度最小的子数组 {
    public int minSubArrayLen(int target, int[] nums) {
        int result=Integer.MAX_VALUE;
        int i=0,sum=0;
        for(int j=0;j<nums.length;j++){
            sum+=nums[j];
            while(sum>=target){
                result=Math.min(result,j-i+1);
                sum-=nums[i];
                i++;
            }
        }
        return result<Integer.MAX_VALUE? result:0;//前面是true则选择result，否则为0
    }
}
